var path = require('path');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
var autoprefixer = require('autoprefixer');

module.exports = {
    entry:{
        bundle:'./src/router/app.js'
    },
    output: {
        path: __dirname+ '/build',
        // filename: "[name].[chunkhash:5].js",
        filename: "[name].js",
        // publicPath:'/build/',
        chunkFilename: '[name].chunk.js',
        // filename: '[name].[chunkhash:8].js', //编译后的文件名字
        // chunkFilename: '[name].[chunkhash:8].js'
    },
    devServer: {
        contentBase: __dirname+ '/build',//本地服务器所加载的页面所在的目录
        historyApiFallback: true,//不跳转
        inline: true//实时刷新
    },
    module: {
        rules: [
            {
                test: /\.css$/, use: 'style-loader!css-loader'
            },
            {
                use: 'babel-loader',
                exclude: /node_modules/,
                test: /\.js[x]?$/
            },
            {
                test: /\.scss$/,
                // use: ['style-loader','css-loader','postcss-loader','sass-loader'],
                use: ExtractTextPlugin.extract({
                  fallback: 'style-loader',
                  //resolve-url-loader may be chained before sass-loader if necessary
                  use: ['css-loader', 'postcss-loader','sass-loader']
                }),
                exclude: /^node_modules$/
            },
            {
                test: /\.css$/,
                use: ['style-loader','css-loader','postcss-loader'],
                exclude: /^node_modules$/
            },
            //file-loader默认编译带了hash值这里是让他用原来的名字
            { test: /\.(png|jpg)$/, use: "file-loader?name=[name].[ext]" }
        ]
    },
    devtool: 'eval-source-map',
    // resolve: {
    //     extensions: ['*','.js', '.jsx'] //后缀名自动补全
    //     // alias: {
    //     //     'Component': __dirname + '/src/scripts/comp-common/index.js',
    //     //     'actions': '../actions/index.js',
    //     //     'Header': './Header.js'
    //     // }
    // }
    // ,
    plugins: [
        new HtmlWebpackPlugin({
          title:'工单系统',
          template:  __dirname + "/src/index.tmpl.html", // 源模板文件
          filename: './index.html', // 输出文件【注意：这里的根路径是module.exports.output.path】
          showErrors: true,
          inject: 'body',
          hash: true
        }),
        new ExtractTextPlugin('style.css')
    ],
};
